import unittest
from Pages.BasePage import webdriver
from utils import Common as cc
from cases import TestCaseInfo
from utils import log as LogUtility
from Pages.LoginPage import LoginPage
import time


class TestLogin(unittest.TestCase):

	def setUp(self):
		self.driver = webdriver.Chrome(cc.driver_path())
		self.base_url = cc.base_url()
#		self.testCaseInfo = TestCaseInfo(id='username',name='password',owner='Edwin ma')
#		self.testResult = TestReport()
		LogUtility.CreateLoggerFile("Test_TC_Login")
		print("setup gogogogogogoggogoo")


	def test_A(self):
		#self.assertEqual(1, 1+1)
		try:
			self.testCaseInfo.starttime = cc.getCurrentTime()
			LogUtility.Log("Open Base site " + self.base_url)
			self.driver.get('http://www.baidu.com')
			self.driver.get(self.base_url)
			time.sleep(5)
			LoginPage.set_username('admin')
			LoginPage.set_password('123456')
			LoginPage.click_SignIn('submit')
			LogUtility.Log("Logging web ...")
			self.testCaseInfo.endtime = cc.getCurrentTime()
		except:
			pass
		'''
	def test_B(self):
		self.assertEqual(1, 2-1)
		LogUtility.Log("Test voer!")
'''


class Test_ok(unittest.TestCase):
	def setUp(self):
		LogUtility.CreateLoggerFile('Test')
		LogUtility.Log("Test start ...")
		print('Test setup run ...')
		self.driver = webdriver.Chrome(cc.driver_path())
		self.base_url = cc.base_url()
	def tearDown(self):
		print("Test teardown ...")

	def test_add(self):
		LogUtility.Log("Add Test....")
		self.driver.get(self.base_url)
		self.driver.find_element_by_id('username').send_keys('admin')
		time.sleep(3)
		self.driver.find_element_by_id('password').send_keys('123456')
		self.driver.find_element_by_name('submit').click()

		self.driver.find_element_by_css_selector('#sysDiv > div > div:nth-child(6)').click()

		time.sleep(1)
		#self.driver.find_element_by_class_name()
	def test_Login_YLZL(self):
		self.driver.get("http://10.1.120.180:9003/hip-portal/com.xinbo.jcmk01.view.portal.d?id=YLZL&name=%E5%8C%BB%E7%96%97%E8%B4%A8%E9%87%8F%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F")
		self.driver.find_element_by_id('username').send_keys('admin')
		time.sleep(2)
		self.driver.find_element_by_id('password').send_keys('123456')
		self.driver.find_element_by_name('submit').click()
		time.sleep(1)
		self.driver.find_element_by_css_selector('div[title="不良事件填报"]').click()

		eles = self.driver.find_elements('xpath', '//*td[@[class="editor"]')
		print(len(eles))




